package Stack;

import java.util.Stack;

/**
 * @Description 验证括号有效性（）{}【】
 * @Author zrj
 * @Date 2020/8/1 11:57
 * @Version 1.0
 */
public class Solution {

    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();

        for (int i = 0 ; i < s.length() ; i ++) {
            char c = s.charAt(i);
            if (c == '(' || c == '【' || c == '{') {
                stack.push(c);
            }else {
                if (stack.isEmpty())
                    return false;
                Character topChar = stack.pop();
                if (c == ')' && topChar != '(')
                    return false;
                if (c == '}' && topChar != '{')
                    return false;
                if (c == '】' && topChar != '【')
                    return false;
            }

        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        System.out.println(isValid("{}【】{{}}"));
    }
}
